home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
music
/
eked-m1.zoo
/
src
/
listwin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-19
|
6KB
|
231 lines
/*
* EKED-M1 : Editor for Korg M1 synth; listwin.c : list windows
* Copyright (C) 1995 Steven M. Eker (Steven.Eker@brunel.ac.uk)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stddef.h>
#include <gemfast.h>
#include <string.h>
#include <stdlib.h>
#include "gm/gem_man.h"
#include "eked-m1.h"
#include "defs.h"
#include "types.h"
#include "externs.h"
#define ROWS 20
typedef struct {
LW_TYPE type;
char title[24];
int selected;
int dest;
BANK *bank;
} LIST_WINDOW;
typedef struct {
DRAG_TYPE drag_type;
int bank_nr;
int item_nr;
} DRAG_ITEM;
static int point_size = 8;
static char *content(int x, int y, long usr_val);
static int action(int handle, E_TYPE type, void *event,
int x_pos, int y_pos, long usr_val);
void ls_size(int size)
{
point_size = size;
}
void ls_window(LW_TYPE type, BANK *bank)
{
LIST_WINDOW *p = MALLOC(LIST_WINDOW);
int t;
if(p == NULL){
fm_alert(1, WINDMEM_ALERT);
return;
}
p->type = type;
strcpy(p->title, type == COMB_LIST ? "Bank 0 Combinations" :
"Bank 0 Programs");
p->title[5] = '0' + bank->bank_nr;
p->selected = NIL;
p->dest = NIL;
p->bank = bank;
t = lm_open((GRECT *) NULL, p->title,
5, ROWS, point_size, 1 + point_size / 4,
13, point_size, WHITE, type == COMB_LIST ? RED : BLUE,
&content, &action, (long) p);
if(t < 0){
FREE(p);
fm_alert(1, t == OUT_OF_MEMORY ? WINDMEM_ALERT : WINDOW_ALERT);
return;
}
if(type == COMB_LIST)
bank->comb_win = t;
else
bank->prog_win = t;
}
static char *content(int x, int y, long usr_val)
{
LIST_WINDOW *p = (LIST_WINDOW *) usr_val;
int n = ROWS * x + y;
BYTE *base;
static char text[15];
text[0] = (n == p->selected || n == p->dest);
text[1] = '0' + n / 10;
text[2] = '0' + n % 10;
text[3] = ' ';
base = (p->type == COMB_LIST) ? COMB_DATA(p->bank, n) : PROG_DATA(p->bank, n);
(void) korg2str(text + 4, base, (size_t) 10);
return text;
}
static int action(int handle, E_TYPE type, void *event,
int x_pos, int y_pos, long usr_val)
{
LIST_WINDOW *p = (LIST_WINDOW *) usr_val;
int n, t;
CLICK *c;
DRAG_DROP *d;
DRAG_ITEM drag_item, *di;
BYTE *item;
switch(type){
case E_CLEANUP:
m1_ctrl(handle, EXITING, 0, 0, (BYTE *) NULL);
if(p->type == COMB_LIST)
p->bank->comb_win = 0;
else
p->bank->prog_win = 0;
FREE(p);
break;
case E_USER:
switch(((int *) event)[0]){
case M1_CTRL_LOST:
t = p->selected;
if(t != NIL){
p->selected = NIL;
lm_update(handle, t / ROWS, t % ROWS);
}
break;
case UPDATE_ITEM:
t = ((int *) event)[1];
lm_update(handle, t / ROWS, t % ROWS);
break;
}
break;
case E_CLICK:
c = (CLICK *) event;
n = ROWS * c->m_x + c->m_y;
t = p->selected;
if(n != t){
p->selected = n;
if(t != NIL)
lm_update(handle, t / ROWS, t % ROWS);
lm_update(handle, n / ROWS, n % ROWS);
}
if(p->type == COMB_LIST){
item = COMB_DATA(p->bank, n);
item[10] = 4; /* convert to a MULTI (if not already) */
m1_ctrl(handle, FORCE_NR | FORCE_DATA, COMB_MODE, n, item);
if(c->n_clks == 2)
ce_window(p->bank, n);
else{
drag_item.drag_type = DRAG_COMB;
drag_item.bank_nr = p->bank->bank_nr;
drag_item.item_nr = n;
lm_dragbox(handle, n / ROWS, n % ROWS, (long) &drag_item);
}
}
else{
item = PROG_DATA(p->bank, n);
m1_ctrl(handle, FORCE_NR | FORCE_DATA, PROG_MODE, n, item);
if(c->n_clks == 2)
pe_window(p->bank, n);
else{
drag_item.drag_type = DRAG_PROG;
drag_item.bank_nr = p->bank->bank_nr;
drag_item.item_nr = n;
lm_dragbox(handle, n / ROWS, n % ROWS, (long) &drag_item);
}
}
break;
case E_DRAG:
d = (DRAG_DROP *) event;
di = (DRAG_ITEM *) d->object;
if(di->drag_type == DRAG_COMB || di->drag_type == DRAG_PROG){
n = ROWS * d->m_x + d->m_y;
t = p->dest;
if(n != t){
p->dest = n;
if(t != NIL && t != p->selected)
lm_update(handle, t / ROWS, t % ROWS);
if(n != p->selected)
lm_update(handle, n / ROWS, n % ROWS);
}
}
break;
case E_DROP:
d = (DRAG_DROP *) event;
di = (DRAG_ITEM *) d->object;
if(di->drag_type == DRAG_COMB || di->drag_type == DRAG_PROG){
t = p->dest;
if(t != NIL){
n= p->bank->bank_nr;
if(p->type == COMB_LIST){
if(di->drag_type == DRAG_COMB){
if(di->bank_nr != n || di->item_nr != t)
ic_combcopy(n, t, di->bank_nr, di->item_nr);
}
else if(di->drag_type == DRAG_PROG)
ic_peffcopy(n, t, di->bank_nr, di->item_nr);
}
else{
if(di->drag_type == DRAG_PROG){
if(di->bank_nr != n || di->item_nr != t)
ic_progcopy(n, t, di->bank_nr, di->item_nr);
}
else if(di->drag_type == DRAG_COMB)
ic_ceffcopy(n, t, di->bank_nr, di->item_nr);
}
}
p->dest = NIL;
if(t != NIL && t != p->selected)
lm_update(handle, t / ROWS, t % ROWS);
}
break;
case E_DRAGEXIT:
d = (DRAG_DROP *) event;
di = (DRAG_ITEM *) d->object;
if(di->drag_type == DRAG_COMB || di->drag_type == DRAG_PROG){
t = p->dest;
p->dest = NIL;
if(t != NIL && t != p->selected)
lm_update(handle, t / ROWS, t % ROWS);
}
break;
}
return R_NORMAL;
}